Getting the number of columns in a table

I have this table where the top cell spans about 7 columns. I am using DOORS 7.1.


My Table

c1 | c2 | c3 | c4 | c5 | c6 | c7 |

c1 | c2 | c3 | c4 | c5 | c6 | c7 |


I am trying to count the number of columns in the entire table (my desired result is 7 in this case), but I am getting mixed results. I use something like this:
Object oCount
Object obj = current

for oCount in row(obj) do {

if(!isMulticolumn) {
curNumColumns = curNumColumns + multicolumn
}
else {
curNumColumns++
}

}

Some Xs are printed based on the value in curNumColumns. Now, when the script finishes, in some tables I will get the right amount of Xs, like |X|X|X|X|X|X|X|. Other times I get a large number of them, about double I think. The top cell has an attribute called multicolumn, I assign it the value 7 to tell my script that it should add 7 to the total amount of columns, and I think this is compounding the problem. When looping through to count columns, am I counting the first cell i.e. the spanning one, or is it the next row? In the documentation I see something about a "header object" that is hidden, could this also be a part of the problem?
mirlo - Sun Mar 21 11:03:48 EDT 2010

Re: Getting the number of columns in a table
mirlo - Sun Mar 21 11:06:50 EDT 2010

By the way, the multicolumn call in the code, is actually:

oCount."multicolumn"

It is assigned, so for this example, just to keep things consistent, we will imagine there is a multicolumn of type int:

int multicolumn =oCount."multicolumn"

I wasn't sure if I could modify my original post or not, so I just replied.

Re: Getting the number of columns in a table
Mathias Mamsch - Mon Mar 22 17:21:32 EDT 2010

Hey Mirlo,

It is hard to say where your problem is, since that "multicolumn" attribute can pretty much have any value. But I can tell you about tables, they are straight forward:

A table consists of a 3-level object hierarchy. All tables have a header object (which you can see, if you choose "hide table cells" from the view menu). Below the header object are the row objects, one for each row in the table. Below each row object there is a cell for each column in a row. So it looks like this:

|- Header
     |-- row 1
     |    |- cell (1,1)
     |    |- cell (1,2) 
     |-- row 2
     |    |- cell (2,1)
     |    |- ...
     |-- ...

 


If you loop with for obj in row obj do {} then you will see all cells in the table row that obj belongs to. If you have a filter set or deleted objects shown you might see less or more cells. But if you don't get the number of rows then it is probably because of the "multicolum" attribute which is incorrectly set.

Regards, Mathias

 

Re: Getting the number of columns in a table
llandale - Mon Mar 22 18:40:28 EDT 2010

Slapped this together on my way out the DOORS ..err.. door.

int  CountColumns(Object oCurr)
{  // Count columns in the Table, of which the Object is a Cell
 
   if (!cell(oCurr)) return(-1)
   oRow = parent(oCurr)
   if (null oRow) return(-1)
   oTable = parent(oCell)
   if (null oTable) return(-1)
 
   CountMax = 0
   CountRow = 0
   for oRow in oTable do
   {  CountRow = 0
      for oCell in oRow do
      {  CountRow++
      }
      if (CountRow > CountMax) CountMax = CountRow
   }
   return(CountMax)
}  // end CountColumns()


-Louie

Re: Getting the number of columns in a table
mirlo - Thu Mar 25 11:41:17 EDT 2010

llandale - Mon Mar 22 18:40:28 EDT 2010

Slapped this together on my way out the DOORS ..err.. door.

int  CountColumns(Object oCurr)
{  // Count columns in the Table, of which the Object is a Cell
 
   if (!cell(oCurr)) return(-1)
   oRow = parent(oCurr)
   if (null oRow) return(-1)
   oTable = parent(oCell)
   if (null oTable) return(-1)
 
   CountMax = 0
   CountRow = 0
   for oRow in oTable do
   {  CountRow = 0
      for oCell in oRow do
      {  CountRow++
      }
      if (CountRow > CountMax) CountMax = CountRow
   }
   return(CountMax)
}  // end CountColumns()


-Louie

I tried the code, but didn't get many results, mostly -1 and 0. I noticed it did not like oCell, so I changed that to oCurr. I am attaching a screenshot showing what I'm up against. I am trying to count the max amount of columns there could be despite some merged cells. I wonder if all this has to do with how I build the tables, adding rows, deleting cells, etc. might be making things worse.
Attachments

attachment_14449807_tables.JPG

Re: Getting the number of columns in a table
llandale - Thu Mar 25 12:43:17 EDT 2010

mirlo - Thu Mar 25 11:41:17 EDT 2010
I tried the code, but didn't get many results, mostly -1 and 0. I noticed it did not like oCell, so I changed that to oCurr. I am attaching a screenshot showing what I'm up against. I am trying to count the max amount of columns there could be despite some merged cells. I wonder if all this has to do with how I build the tables, adding rows, deleting cells, etc. might be making things worse.

//************************
int    CountColumns(Object oCurr, bool ConsiderDeletes)
{     // Count columns in the Table, of which the Object is a Cell
        // When  ConsiderDeletes, count deleted rows and Cells,
        //     otherwise ignore deleted rows and cells
 
        if (null oCurr) return(-1)
 
        Object  oRow, oTable, oCell
        int     CountMax, CountRow
 
        if    (table(oCurr)) oTable = oCurr
        elseif(row(oCurr))   oTable = parent(oCurr)
        elseif(cell(oCurr)) 
        {  oRow = parent(oCurr)
           if (null oRow) return(-1)
           oTable = parent(oRow)
        }
        else return(-1)   // oCurr is not part of a table
        if (null oTable) return(-1)     // Cannot determine Table object
 
        CountMax = 0
        CountRow = 0
        for oRow in table(oTable) do
        {  if(!ConsiderDeletes and isDeleted(oRow)) continue
           CountRow = 0
           for oCell in row(oRow) do
           {  if (!ConsiderDeletes and isDeleted(oCell)) continue
              CountRow++
           }
           if (CountRow > CountMax) CountMax = CountRow
        }
        return(CountMax)
}  // end CountColumns()
 
print "Count = " CountColumns(current Object, true) "\n"
print "Count = " CountColumns(current Object, false) "\n"

Re: Getting the number of columns in a table
mirlo - Thu Apr 29 10:44:28 EDT 2010

llandale - Thu Mar 25 12:43:17 EDT 2010

//************************
int    CountColumns(Object oCurr, bool ConsiderDeletes)
{     // Count columns in the Table, of which the Object is a Cell
        // When  ConsiderDeletes, count deleted rows and Cells,
        //     otherwise ignore deleted rows and cells
 
        if (null oCurr) return(-1)
 
        Object  oRow, oTable, oCell
        int     CountMax, CountRow
 
        if    (table(oCurr)) oTable = oCurr
        elseif(row(oCurr))   oTable = parent(oCurr)
        elseif(cell(oCurr)) 
        {  oRow = parent(oCurr)
           if (null oRow) return(-1)
           oTable = parent(oRow)
        }
        else return(-1)   // oCurr is not part of a table
        if (null oTable) return(-1)     // Cannot determine Table object
 
        CountMax = 0
        CountRow = 0
        for oRow in table(oTable) do
        {  if(!ConsiderDeletes and isDeleted(oRow)) continue
           CountRow = 0
           for oCell in row(oRow) do
           {  if (!ConsiderDeletes and isDeleted(oCell)) continue
              CountRow++
           }
           if (CountRow > CountMax) CountMax = CountRow
        }
        return(CountMax)
}  // end CountColumns()
 
print "Count = " CountColumns(current Object, true) "\n"
print "Count = " CountColumns(current Object, false) "\n"

Thanks, this worked very well. When I tried it on a larger document however, there were a few issues, of which I think I narrowed it down. It turns out that things are getting confused when there are filters filtering out some cells. My view is set up, it shows the table I want, but the column count is off somehow. I want to count only those columns that are visible in my view. I took a quick look at the documentation and there is a isVisible call, but I will have to try that tomorrow. Could this be the problem?

Re: Getting the number of columns in a table
llandale - Thu Apr 29 11:59:03 EDT 2010

mirlo - Thu Apr 29 10:44:28 EDT 2010
Thanks, this worked very well. When I tried it on a larger document however, there were a few issues, of which I think I narrowed it down. It turns out that things are getting confused when there are filters filtering out some cells. My view is set up, it shows the table I want, but the column count is off somehow. I want to count only those columns that are visible in my view. I took a quick look at the documentation and there is a isVisible call, but I will have to try that tomorrow. Could this be the problem?

Looking at the documentation, I see that the "for oCell in row(oRow)" loop respects the display set, ignoring cells you don't see. I presume that is also for the "for oRow in table(oTable) loop.

The "for oChild in oParent" loop ignores the display set. I don't see why you cannot use that loop in place of the other two above. If you want to ignore invisible objects, then yes try "if (!isVisible(obj)) continue".

  • Louie

Re: Getting the number of columns in a table
Salo33 - Tue Jul 05 07:30:17 EDT 2016

Hi Everyone,

Please help me in the problem about the total number columns and rows in csv file. Is there anyway to find the total number of rows and columns of the csv file through the dxl script ? Actually one might ask that why I need it because I have the application which import the data from csv file to doors module and now the total number of rows and columns option is manual in it( I enter the number of rows and columns manually in the code), so I want to automate this option.

A help will be highly appreciated.

Thanks

Re: Getting the number of columns in a table
DOORSHAM - Tue Jul 05 09:36:19 EDT 2016

Salo33 - Tue Jul 05 07:30:17 EDT 2016

Hi Everyone,

Please help me in the problem about the total number columns and rows in csv file. Is there anyway to find the total number of rows and columns of the csv file through the dxl script ? Actually one might ask that why I need it because I have the application which import the data from csv file to doors module and now the total number of rows and columns option is manual in it( I enter the number of rows and columns manually in the code), so I want to automate this option.

A help will be highly appreciated.

Thanks

Create a stream and read in the first line of csv file.

Count the number of commas,  This is based on assumptions you haven't deliminated any commas in heading line.

Re: Getting the number of columns in a table
Salo33 - Tue Jul 05 10:49:11 EDT 2016

DOORSHAM - Tue Jul 05 09:36:19 EDT 2016

Create a stream and read in the first line of csv file.

Count the number of commas,  This is based on assumptions you haven't deliminated any commas in heading line.

Dear Sir,

I am new to door and not having experience, so could you please write the dxl code for finding the number of rows and columns in the dxl.

Thanks

Re: Getting the number of columns in a table
DOORSHAM - Tue Jul 05 12:11:55 EDT 2016

Salo33 - Tue Jul 05 10:49:11 EDT 2016

Dear Sir,

I am new to door and not having experience, so could you please write the dxl code for finding the number of rows and columns in the dxl.

Thanks

LOL